package com.example.ipcdemo;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.view.View;
import android.widget.Toast;

import com.example.ipcdemo.bean.UserInfo;
import com.example.lib_ipc.core.UserBinderIPC;

public class SecActivity extends AppCompatActivity {
    IUserSingleton userService = null;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sec);
//            Toast.makeText(this, "info" + info.toString(), Toast.LENGTH_SHORT).show();
        //另外一个进程
        //1.打开服务
        UserBinderIPC.getInstance().open(this);

    }

    public void start(View view) {
        //2.获取到接口实现类
        IUserSingleton instance = UserBinderIPC.getInstance().getInstance(IUserSingleton.class, "Get");
        UserInfo userInfo = instance.getUserInfo();
        if (userInfo != null) {
            Toast.makeText(this, "info" + userInfo.toString(), Toast.LENGTH_SHORT).show();
        }
    }

    public void setName(View view) {
        IUserSingleton instance = UserBinderIPC.getInstance().getInstance(IUserSingleton.class, "Get");
        instance.setUserName("username");
    }

    public void getName(View view) {
        IUserSingleton instance = UserBinderIPC.getInstance().getInstance(IUserSingleton.class, "Get");
        String userName = instance.getUserName();
        Toast.makeText(this, "userName:" + userName, Toast.LENGTH_SHORT).show();
    }

    public void download(View view) {
        IDownloadSingleton instance1= UserBinderIPC.getInstance().getInstance(IDownloadSingleton.class);
        String download = instance1.download("baidu.com");
        Toast.makeText(this, download, Toast.LENGTH_SHORT).show();
    }
}